<?php

namespace App\Containers\AppSection\Project\Models;

use App\Containers\AppSection\File\Models\File;
use App\Ship\Parents\Models\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Staudenmeir\EloquentJsonRelations\HasJsonRelationships;
use Staudenmeir\EloquentJsonRelations\Relations\BelongsToJson;

/**
 * Документы проекта
 *
 * @property int $id Id
 * @property int $project_id Проект
 * @property string $label Описание
 * @property bool $required Обязательно
 *
 * @property Project $project Проект
 * @property File[] $files Фвйлы
 */
class Document extends Model
{
    use HasJsonRelationships;

    public $timestamps = false;
    protected $table = 'project_documents';
    protected $fillable = [
        'project_id',
        'label',
        'required',
        'files',
    ];

    protected $attributes = [

    ];

    protected $hidden = [

    ];

    protected $casts = [
        'files' => 'json',
    ];

    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Document';

    /**
     * Файлы
     * @return BelongsToJson Files
     */
    public function files(): belongsToJson
    {
        return $this->belongsToJson(File::class, 'files');
    }

    /**
     * Проект
     * @return BelongsTo Project
     */
    public function project(): BelongsTo
    {
        return $this->belongsTo(Project::class, 'project_id', 'id');
    }
}
